package cn.peach.mq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 */
public class mq_01 {
    public static final String NAME_QUEUE_HELLO = "NAME_QUEUE_HELLO";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        //factory.setUsername(userName);
        //factory.setPassword(password);
        //factory.setVirtualHost(virtualHost);
        factory.setHost("115.159.88.63");
        //factory.setPort(portNumber);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        /*队列名，队列持久化，独占连接，删除队列*/
        channel.queueDeclare(NAME_QUEUE_HELLO,true,false, false, null);
        channel.basicPublish("", NAME_QUEUE_HELLO, null, "发送消息".getBytes());
        System.out.println("消息发送搞定");
    }
}
